import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/controller/SearchController.dart';
import 'package:get/get.dart';

class SearchWidget extends StatelessWidget {
  SearchController _searchController = Get.put(SearchController());

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      //外边距
      margin: EdgeInsets.all(22),
      //内边距
      padding: EdgeInsets.all(12),
      //圆角边框
      decoration: BoxDecoration(
        color: Colors.white,
        //四个圆角的大小
        borderRadius: BorderRadius.all(Radius.circular(10)),
      ),
      //线性排列
      child: Column(
        //左对齐
        crossAxisAlignment: CrossAxisAlignment.start,
        //填充
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(
            "搜索",
            style: TextStyle(
              fontWeight: FontWeight.w600,
            ),
          ),
          Container(
            //外边距 上边距
            margin: EdgeInsets.only(top: 12),
            //内边距 左右
            padding: EdgeInsets.only(left: 12, right: 12),
            decoration: BoxDecoration(
                color: Colors.white,
                //四个圆角大小
                borderRadius: BorderRadius.all(Radius.circular(12)),
                //边框颜色以及宽度
                border: Border.all(color: Colors.grey, width: 1.0)),
            child: Row(
              children: [
                Expanded(
                  //输入框
                  child: TextField(
                    controller: _searchController,
                    onSubmitted: (value) {
                      _searchController.search(context, value);
                    },
                    decoration: InputDecoration(
                      hintText: "请输入要搜索的内容",
                      //隐藏输入框背景
                      border: InputBorder.none,
                    ),
                  ),
                ),
                //搜索图标
                IconButton(
                  onPressed: () {
                    String inputStr = _searchController.text;
                    _searchController.search(context, inputStr);
                  },
                  icon: Icon(Icons.search),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
